/**
 * 
 */
package info.niwota.commons;

import java.io.File;

import android.os.Environment;
import android.os.StatFs;

/**
 * @author qiangli
 * 
 */
public final class SDCard {
	public static boolean checkSDCard() {
		String state = Environment.getExternalStorageState();
		if (state.equals(Environment.MEDIA_REMOVED)
				|| state.equals(Environment.MEDIA_UNMOUNTED)
				|| state.equals(Environment.MEDIA_MOUNTED_READ_ONLY)
				|| state.equals(Environment.MEDIA_UNMOUNTABLE)) {
			return false;
		}
		return true;
	}

	public static boolean hasStorage() {
		String state = Environment.getExternalStorageState();
		return (Environment.MEDIA_MOUNTED.equals(state));
	}

	public static File getTop() {
		File dir = Environment.getExternalStorageDirectory();
		return dir;
	}
	
	private SDCard() {
		super();
	}
	
	public static long availableSpace() {
		File sdcard = Environment.getExternalStorageDirectory();
		StatFs stat = new StatFs(sdcard.getPath());
		long avail = stat.getAvailableBlocks() * (long) stat.getBlockSize();
		return avail;
	}
	
	public static long totalSpace() {
		File sdcard = Environment.getExternalStorageDirectory();
		StatFs stat = new StatFs(sdcard.getPath());
		long total = stat.getBlockCount() * (long) stat.getBlockSize();
		return total;
	}
}
